﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataLayer.Configuration;
using System.Data.SqlClient;
using Microsoft.Data.Objects;

namespace DataLayer
{
    public class DataContext
    {

        public static Model FactoryDataContext()
        {
            String connection = @"Data Source=.\SQLEXPRESS;Initial Catalog=EF4Inheritance;Integrated Security=SSPI;";
            var builder = new ContextBuilder<Model>();
            builder.Configurations.Add(new PersonConfiguration());
            builder.Configurations.Add(new AcademicPersonConfiguration());

            return builder.Create(new SqlConnection(connection));
        }

        public static void CreateDataBase()
        {

            var ctx = FactoryDataContext();
            if (ctx.DatabaseExists())
                ctx.DeleteDatabase();
            ctx.CreateDatabase();

        }

    }
}
